public class Liczba {
	
	
	public int n;
	public String[] systemy;
	public char[] znaki = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };

//.
	Liczba() {
	}


	

	Liczba(int n) {
		systemy = new String[17];

		for (int i = 2; i <= 16; i++) {

			this.n = n;
			if ( i != 10 ) {
				systemy[i] = zapis(i);
				System.out.println(10 + ":" + n + " --->> " + i + ":" + systemy[i]);
			}
			else
				systemy[i] = "" + n;
		}
}
//jakis tam edit do commita



	Liczba(String n, int podstawa) throws LiczbaException {
		systemy = new String[17];
		int tmp;
		String wyrazenie = "";
		try {
			switch (podstawa) {
				case 2:
				case 3:
				case 4:
				case 5:
				case 6:
				case 7:
				case 8:
				case 9:
				case 10: wyrazenie = "[0-" + (podstawa-1) + "]+"; break;
				case 11: wyrazenie = "[0-9a]+"; break;
				case 12: wyrazenie = "[0-9a-b]+"; break;
				case 13: wyrazenie = "[0-9a-c]+"; break;
				case 14: wyrazenie = "[0-9a-d]+"; break;
				case 15: wyrazenie = "[0-9a-e]+"; break;
				case 16: wyrazenie = "[0-9a-f]+"; break;
				default: throw new LiczbaException( "1" );
			}

			n.replaceAll("A", "a");
			n.replaceAll("B", "b");
			n.replaceAll("C", "c");
			n.replaceAll("D", "d");
			n.replaceAll("E", "e");
			n.replaceAll("F", "f");

			if ( !n.matches( wyrazenie ) )
				throw new LiczbaException("2");

			for (char c : n.toCharArray() ) {
				this.n *= podstawa;
				tmp = 0;

				while ( c != znaki[tmp] )
					tmp += 1;

				this.n += tmp;
			}

			tmp = this.n;

			for (int i = 2; i <= 16; i++) {
				this.n = tmp;
				if ( i != podstawa ) {
					systemy[i] = zapis(i);
					System.out.println(podstawa + ":" + n + " --->> " + i + ":" + systemy[i]);
				}
				else
					systemy[i] = "" + this.n;
			}
		}
		catch ( LiczbaException w ) {
			if ( w.equals( "1" ) )
				System.out.println("Blad! Podstawa systemu musi byc liczba z zakresu 2-16.");
			if ( w.equals( "2" ) )
				System.out.println("Blad! Podana liczba zawiera znaki niedozwolone dla wybranego systemu.");
		} 
	}




	public String zapis(int podstawa) {
		String zapis = "";
		int tmp = 0;

		while ( n > 0 ) {
			tmp = n % podstawa;
			zapis = znaki[tmp] + zapis;
			n /= podstawa;
		}

		return zapis;
	}
}